import Dialog from './Dialog.vue'

export default {
  install(Vue) {
    Vue.prototype.$dialog = {
      show(options) {
        return new Promise((resolve) => {
          const Constructor = Vue.extend(Dialog)
          const instance = new Constructor({
            propsData: options
          })
          instance.$mount()
          document.body.appendChild(instance.$el)
          // 确保在组件挂载后调用 resolve 方法，传递实例以便外部使用
          instance.$once('hook:beforeDestroy', () => {
            resolve(instance)
          })
        })
      }
    }
  }
}